// AccessRepeater.h
//
// Keeps track of multiple memory accesses per instruction and serves up data
// if its asked for repeatedly in the same instruction. This avoids going to
// the cache multiple times for the same operation.
//
// Call reset() before you go to execute an instruction. If the instruction
// succeeds, call clear().
//
#ifndef _ACCESSREPEATER_H__
#define _ACCESSREPEATER_H__
#define MAX_ACCESSES 4096

#include "base/simtypes.h"

typedef struct {
    VA             address;
    uint           data[MAX_BLOCK_SIZE/WORD_SIZE];
    WordAccessType type;
} RepeatedAccess;

class AccessRepeater {
  public:
    AccessRepeater();

    void clear();
    void reset();
    bool isRegistered();
    void skip();
    void getValue(VA wordAddress, WordAccessType type, uint* dest);
    void registerAccess(VA wordAddress, uint* data, WordAccessType type);

  protected:
    RepeatedAccess accesses[MAX_ACCESSES];
    uint walk;
    uint count;
};
#endif // _ACCESSREPEATER_H__
